﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using BOSS.Dao.Security;
using BOSS.Domain.Security;

using NHibernate;
using NHibernate.Criterion;

namespace BOSS.Dao.NHibernate.Security
{
    public class LoginInfoDao : EntityDao<LoginInfo, int>, ILoginInfoDao
    {
        #region ILoginInfoDao Members

        public LoginInfo FindByGuid(Guid guid, string ip)
        {
            IList<LoginInfo> loginInfos = this.HibernateTemplate.ExecuteFind<LoginInfo>(delegate(ISession session)
            {
                ICriteria criteria = session.CreateCriteria(typeof(LoginInfo), "l");
                criteria.Add(Expression.Eq("l.Guid", guid));
                criteria.Add(Expression.Eq("l.IpAddress", ip));
                return criteria.SetFetchSize(1).List<LoginInfo>();
            });

            return loginInfos.FirstOrDefault();
        }

        #endregion

        [Spring.Transaction.Interceptor.Transaction(ReadOnly=false)]
        public new void SaveOrUpdate(LoginInfo info)
        {
            base.SaveOrUpdate(info);
        }

        [Spring.Transaction.Interceptor.Transaction(ReadOnly = false)]
        public new int Save(LoginInfo info)
        {
            return base.Save(info);
        }
    }
}
